﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace Gola.VN.Scb.Web.Dal
{
    public static class DalUtilities
    {
        public static string ConnectionString { set; get; }
        private static SqlConnection _sqlConn;

        public static bool ExistConnection
        {
            get
            {
                return (_sqlConn != null &&
                    (_sqlConn.State == ConnectionState.Open ||
                    _sqlConn.State == ConnectionState.Connecting ||
                    _sqlConn.State == ConnectionState.Executing ||
                    _sqlConn.State == ConnectionState.Fetching));
            }
        }

        public static SqlConnection GetConnection()
        {
            if (_sqlConn == null)
            {
                _sqlConn = new SqlConnection(ConnectionString);
                _sqlConn.Open();
            }

            if (_sqlConn.State == ConnectionState.Closed)
            {
                if (string.IsNullOrEmpty(_sqlConn.ConnectionString))
                    _sqlConn.ConnectionString = ConnectionString;
                _sqlConn.Open();
            }

            return _sqlConn;
        }

        public static void Dispose()
        {
            // _sqlConn.Close();
            // _sqlConn.Dispose();
        }

    }
}
